﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;
using MAF.Common;

namespace MAF.UserSecurity
{
    /// <summary>
    /// 用户
    /// </summary>
    public class User : IIdentity
    {
        #region 构造方法

        /// <summary>
        /// 构造方法
        /// </summary>
        public User()
        {
            // 初始化属性
            Id = CombGuid.NewGuid();
            Name = string.Empty;
            Password = "123456";
            IsAuthenticated = false;

            CreatedBy = Guid.Empty;
            CreatedOn = DateTime.Now;
            ModifiedBy = null;
            ModifiedOn = null;
        }

        #endregion

        #region 属性

        /// <summary>
        /// ID
        /// </summary>
        public Guid Id { get; private set; }

        /// <summary>
        /// 用户名
        /// </summary>
        public string Name { get; set; }
        
        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get; set; }

        #region IIdentity 成员

        /// <summary>
        /// 授权类型，此属性可以持久化到数据源，用来在登录时区分不同的认证类型
        /// </summary>
        public string AuthenticationType
        {
            get { return "MAF"; }
        }

        /// <summary>
        /// 是否已经通过认证（即是否已经登录）
        /// </summary>
        public bool IsAuthenticated 
        {
            get;
            internal set;   // 由Authenticator.Login方法设置为true
        }

        /// <summary>
        /// 用户名，跟已有属性重名
        /// </summary>
        //public string Name { get; private set; }

        #endregion

        #region 对象更新历史记录

        public Guid CreatedBy { get; set; }

        public Guid? ModifiedBy { get; set; }

        public DateTime CreatedOn { get; set; }

        public DateTime? ModifiedOn { get; set; }

        #endregion

        #endregion
    }
}
